package j02object;

import java.io.*;

class Dog implements Serializable{
    String name;
    String sex;

    public Dog(String name, String sex) {
        this.name = name;
        this.sex = sex;
    }
}

class Man implements Serializable {
    String name;
    //不会存储
    transient int age;
    Dog pet;

    public Man(String name, int age, Dog pet) {
        this.name = name;
        this.age = age;
        this.pet = pet;
    }

}

public class J2 {
    public static void main(String[] args) throws Exception {
        ObjectOutputStream f = new ObjectOutputStream(
                new FileOutputStream("_1219\\src\\j02object\\b.txt")
        );
        f.writeObject(
                new Man("john",45,new Dog("拉多","公"))
        );
        f.close();
    }
}
class J3read{
    public static void main(String[] args) throws Exception {
        ObjectInputStream f = new ObjectInputStream(
                new FileInputStream("_1219\\src\\j02object\\b.txt")
        );
        Man m = (Man)f.readObject();
        System.out.println("m.name = " + m.name);
        System.out.println("m.age = " + m.age);
    }
}
